<?php

/**
 * This function extracts the phone number.
 *
 * @param string $from
 *                     The remitter delivered by WHATSAPP example 1234567890@s.whatsapp.net
 *
 * @return string
 *                Returns the number of phone cleanly.
 **/
function ExtractNumber($from)
{
    return str_replace(['@s.whatsapp.net', '@g.us'], '', $from);
}
function pkcs5_unpad($text)
{
    $pad = ord($text{strlen($text) - 1});
    if ($pad > strlen($text)) {
        return false;
    }
    if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
        return false;
    }

    return substr($text, 0, -1 * $pad);
}

function wa_pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
    $algorithm = strtolower($algorithm);
    if (!in_array($algorithm, hash_algos(), true)) {
        die('PBKDF2 ERROR: Invalid hash algorithm.');
    }
    if ($count <= 0 || $key_length <= 0) {
        die('PBKDF2 ERROR: Invalid parameters.');
    }

    $hash_length = strlen(hash($algorithm, '', true));
    $block_count = ceil($key_length / $hash_length);

    $output = '';
    for ($i = 1; $i <= $block_count; $i++) {
        $last = $salt.pack('N', $i);
        $last = $xorsum = hash_hmac($algorithm, $last, $password, true);
        for ($j = 1; $j < $count; $j++) {
            $xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
        }
        $output .= $xorsum;
    }

    if ($raw_output) {
        return substr($output, 0, $key_length);
    } else {
        return bin2hex(substr($output, 0, $key_length));
    }
}

function preprocessProfilePicture($path)
{
    list($width, $height) = getimagesize($path);
    if ($width > $height) {
        $y = 0;
        $x = ($width - $height) / 2;
        $smallestSide = $height;
    } else {
        $x = 0;
        $y = ($height - $width) / 2;
        $smallestSide = $width;
    }

    $size = 639;
    $image = imagecreatetruecolor($size, $size);
    $img = imagecreatefromstring(file_get_contents($path));

    imagecopyresampled($image, $img, 0, 0, $x, $y, $size, $size, $smallestSide, $smallestSide);
    ob_start();
    imagejpeg($image);
    $i = ob_get_contents();
    ob_end_clean();

    imagedestroy($image);
    imagedestroy($img);

    return $i;
}

function createIcon($file)
{
    if ((extension_loaded('gd')) && (file_exists($file))) {
        return createIconGD($file);
    } else {
        return base64_decode(giftThumbnail());
    }
}

function createIconGD($file, $size = 100, $raw = true)
{
    list($width, $height) = getimagesize($file);
    if ($width > $height) {
        $y = 0;
        $x = ($width - $height) / 2;
        $smallestSide = $height;
    } else {
        $x = 0;
        $y = ($height - $width) / 2;
        $smallestSide = $width;
    }

    $image_p = imagecreatetruecolor($size, $size);
    $image = imagecreatefromstring(file_get_contents($file));

    imagecopyresampled($image_p, $image, 0, 0, $x, $y, $size, $size, $smallestSide, $smallestSide);
    ob_start();
    imagejpeg($image_p);
    $i = ob_get_contents();
    ob_end_clean();

    imagedestroy($image);
    imagedestroy($image_p);

    return $i;
}

function createVideoIcon($file)
{
    /* should install ffmpeg for the method to work successfully  */
    if (checkFFMPEG()) {
        //generate thumbnail
        $preview = sys_get_temp_dir().'/'.md5($file).'.jpg';
        @unlink($preview);

        //capture video preview
        $command = 'ffmpeg -i "'.$file.'" -f mjpeg -ss 00:00:01 -vframes 1 "'.$preview.'"';
        exec($command);

        return createIconGD($preview);
    } else {
        return base64_decode(videoThumbnail());
    }
}

function checkFFMPEG()
{
    //check if ffmpeg is installed.
    $output = [];
    $returnvalue = false;

    exec('ffmpeg -version', $output, $returnvalue);

    return $returnvalue === 0;
}

function giftThumbnail()
{
    return '/9j/4AAQSkZJRgABAQEASABIAAD/4QCURXhpZgAASUkqAAgAAAADADEBAgAcAAAAMgAAADIBAgAUAAAATgAAAGmHBAABAAAAYgAAAAAAAABBZG9iZSBQaG90b3Nob3AgQ1MyIFdpbmRvd3MAMjAwNzoxMDoyMCAyMDo1NDo1OQADAAGgAwABAAAA//8SAAKgBAABAAAAvBIAAAOgBAABAAAAoA8AAAAAAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdCIFhZWiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLUhQICAAAAAAAAAAAAAAAAAAAAAAAAAAAA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2E0AmBZce1uWNUG/5xawsTfg6+zn8rM3Cn46htI9ZLL4RP9Pecfz6++pMq+f45kd/lnZaxVxQKA5Y+oI/LuTahr8BzSd4/6xet+8ufuM9k+tGqb4q25x/vXUxjTKCYbBXZWznKjYbmORuICPbVrRbKQuY9H2eAVY0Y8pC4YI+yNqjaIZSFqxR7OFWNETkLJikHDhUTI3IVzJELF7KjZY2KlogA24VEylpoNmNuXXOaGt2RSo/hLWDiL8JX2c/lZm4U/G0NpDrRIj4RSyJen7OEhUKCn/fnvgvx8TFmIcPkGuBRzI+g5Z2Wu1cWn4Nfhb0CFwoDnh3j0ub5ktr7HeMtWT8zGSOSychGycc3Mugqi6drLJKJqkAwCBk1AuFrgPAbCFejheK3jDK3613aUrLMqtTT5LDEvtxpXyn+nVVqtt5sozanSv1AIcf/AIrmNg9P2esIfgSrYuPsV70NRaTyHurcXyS1uw8y9OXUMh83pjLwt+7V/oacfYr3oai0kb3Rw98ktbsPcmiepdH5rTWXcO+NW+hpx9ivehqLSWvc7DnyT1noMkun+qlH5rTWWcP3Wr9DVOPcU56eotJbwZhvNPWegyC6z6ukfmtN5X8sUp9DVOPMU56ep2lvBWG809d6D2Lg/WWl81pnKf8AiT/Q1TjrE+enqdpTgjDOaeu9B7FxrraS+b0zlFg7P9oN9DVOOcS/16naU4Hwzmnr9hkkiOuwogCOlsnMPoD7HH6Gqcb4l/r1O0pwPhnNPX7DEnsM698mhn0G70llAMpFPy3HLGeWIlvew2IQRD1XrHvO92IXilKlJwSkrHZGx2PPltdlpPddz8Ou1WNWMZOUXarZNq1ZnZZyE0/h6aF6idVsX5c3xh1iOPykoZ8ES/EpHJjAkRIyp0wMPLzCXgA8eF61k2guO5T+Ty38XLb5aA9qALUB8sHdQBYO4KALB3BQBYO4KALB3BQBYO4KALB3BQBYO6gCwd1AfaAKAKAKAKAKAKAKAKAKAKAKAKAKAKA//9k=';
}
function updateData($nameFile, $WAver, $WAToken = null)
{
    $file = __DIR__.'/'.$nameFile;
    $open = fopen($file, 'r+');
    $content = fread($open, filesize($file));
    fclose($open);

    $content = explode("\n", $content);

    if ($file == __DIR__.'/token.php') {
        $content[27] = '    $releaseTime = \''.$WAToken.'\';';
    } else {
        if ($file == __DIR__.'/Constants.php') {
            $content[21] = '    const WHATSAPP_VER = \''.trim($WAver).'\';                                                          // The WhatsApp version.';
            $content[22] = '    const WHATSAPP_USER_AGENT = \'WhatsApp/'.trim($WAver).' S40Version/14.26 Device/Nokia302\';         // User agent used in request/registration code.';
        }
    }

    $content = implode("\n", $content);

    file_put_contents($file, $content);
}

/**
 * This function generates a paymentLink where you can extend the account-expiration.
 *
 * @param string $number Your number with international code, e.g. 49123456789
 * @param int    $sku    The Time in years (1, 3 or 5) you want to extend the account-expiration.
 *
 * @return string Returns the link.
 **/
function generatePaymentLink($number, $sku)
{
    return sprintf('https://www.whatsapp.com/payments/cksum_pay.php?phone=%s&cksum=%s&sku=%d',
        $number,
        md5($number.'abc'),
        $sku,
        ($sku != 1 && $sku != 3 && $sku != 5) ? 1 : $sku);
}

// Gets mime type of a file using various methods
function get_mime($file)
{
    if (function_exists('finfo_file')) {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($finfo, $file);
        finfo_close($finfo);

        return $mime;
    }

    if (function_exists('mime_content_type')) {
        return mime_content_type($file);
    }

    if (!strncasecmp(PHP_OS, 'WIN', 3) == 0 && !stristr(ini_get('disable_functions'), 'shell_exec')) {
        $file = escapeshellarg($file);
        $mime = shell_exec('file -b --mime-type '.$file);

        return trim($mime);
    }

    return false;
}

function getExtensionFromMime($mime)
{
    $extensions = [
      'audio/3gpp'      => '3gp',
      'audio/x-caf'     => 'caf',
      'audio/wav'       => 'wav',
      'audio/mpeg'      => 'mp3',
      'audio/mpeg3'     => 'mp3',
      'audio/x-mpeg-3'  => 'mp3',
      'audio/x-ms-wma'  => 'wma',
      'audio/ogg'       => 'ogg',
      'audio/aiff'      => 'aif',
      'audio/x-aiff'    => 'aif',
      'audio/aac'       => 'aac',
      'audio/mp4'       => 'm4a',
      'image/jpeg'      => 'jpg',
      'image/gif'       => 'gif',
      'image/png'       => 'png',
      'video/3gpp'      => '3gp',
      'video/mp4'       => 'mp4',
      'video/quicktime' => 'mov',
      'video/avi'       => 'avi',
      'video/msvideo'   => 'avi',
      'video/x-msvideo' => 'avi',
  ];

    return $extensions[$mime];
}

function adjustId($id)
{
    $data = strrev(pack('L', $id));
    $data = bin2hex(ltrim($data));
    while (strlen($data) < 6) {
        $data = '0'.$data;
    }

    return hex2bin($data);
}

function deAdjustId($data)
{
    if (strlen($data) < 4) {
        $data = "\x00".$data;
    }
    $data = strrev($data);
    $data = unpack('L', $data);

    return $data[1];
}

function unpadV2Plaintext($v2plaintext)
{
    if (strlen($v2plaintext) < 128) {
        return substr($v2plaintext, 2, -1);
    } else {
        return substr($v2plaintext, 3, -1);
    }
}
function parseText($txt)
{
    for ($x = 0; $x < strlen($txt); $x++) {
        if (ord($txt[$x]) < 20 || ord($txt[$x]) > 230) {
            $txt = 'HEX:'.bin2hex($txt);

            return $txt;
        }
    }

    return $txt;
}
function niceVarDump($obj, $ident = 0)
{
    $data = '';
    $data .= str_repeat(' ', $ident);
    $original_ident = $ident;
    $toClose = false;
    switch (gettype($obj)) {
        case 'object':
            $vars = (array) $obj;
            $data .= gettype($obj).' ('.get_class($obj).') ('.count($vars).") {\n";
            $ident += 2;
            foreach ($vars as $key => $var) {
                $type = '';
                $k = bin2hex($key);
                if (strpos($k, '002a00') === 0) {
                    $k = str_replace('002a00', '', $k);
                    $type = ':protected';
                } elseif (strpos($k, bin2hex("\x00".get_class($obj)."\x00")) === 0) {
                    $k = str_replace(bin2hex("\x00".get_class($obj)."\x00"), '', $k);
                    $type = ':private';
                }
                $k = hex2bin($k);
                if (is_subclass_of($obj, 'ProtobufMessage') && $k == 'values') {
                    $r = new ReflectionClass($obj);
                    $constants = $r->getConstants();
                    $newVar = [];
                    foreach ($constants as $ckey => $cval) {
                        if (substr($ckey, 0, 3) != 'PB_') {
                            $newVar[$ckey] = $var[$cval];
                        }
                    }
                    $var = $newVar;
                }
                $data .= str_repeat(' ', $ident)."[$k$type]=>\n".niceVarDump($var, $ident)."\n";
            }
            $toClose = true;
        break;
        case 'array':
            $data .= 'array ('.count($obj).") {\n";
            $ident += 2;
            foreach ($obj as $key => $val) {
                $data .= str_repeat(' ', $ident).'['.(is_int($key) ? $key : "\"$key\"")."]=>\n".niceVarDump($val, $ident)."\n";
            }
            $toClose = true;
        break;
        case 'string':
            $data .= 'string "'.parseText($obj)."\"\n";
        break;
        case 'NULL':
            $data .= gettype($obj);
        break;
        default:
            $data .= gettype($obj).'('.strval($obj).")\n";
        break;
    }
    if ($toClose) {
        $data .= str_repeat(' ', $original_ident)."}\n";
    }

    return $data;
}
function encodeInt7bit($value)
{
    $v = $value;
    $out = '';
    while ($v >= 0x80) {
        $out .= chr(($v | 0x80) % 256);
        $v >>= 7;
    }
    $out .= chr($v % 256);

    return $out;
}

function padMessage($plaintext)
{
    $padded = '';
    $padded .= chr(10);
    $padded .= encodeInt7bit(strlen($plaintext));
    $padded .= $plaintext;
    $padded .= chr(1);

    return $padded;
}

function randomStr($length)
{
    $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

    $string = '';
    for ($i = 0; $i < $length; $i++) {
        $string .= $characters[mt_rand(0, strlen($characters) - 1)];
    }

    return $string;
}

function getRandomGCM()
{
    return randomStr(5).'_'.randomStr(5).':'.'APA91b'.randomStr(64).
         '_'.randomStr(5).'-'.randomStr(12).'_'.randomStr(9).
         '_'.randomStr(11).'_'.randomStr(1).'_'.randomStr(26);
}
